from decimal import Decimal

import pytest

# 待测函数
def add(a, b):
    if isinstance(a,float) or isinstance(b, float):
        # return "%.2f"%(a + b)
        return Decimal(str(a)) + Decimal(str(b))
    return a + b
# 对测试类进行多个参数化
# @pytest.mark.parametrize('a, b, c', [(1,2,3), (4,5,9)])
# class TestAdd():
#     def test_add1(self, a, b, c):
#         assert add(a, b) == c
#
#     def test_add2(self, a, b, c):
#         assert add(a, b) == c

# ids的作用，修改结果显示名称
data = [[1,2,3,'整数相加'], [-1,-2,-3,'负数相加'], ['1', '2', '12','字符窜相加']]
# 生成与数据量相同的名称列表
ids = [d.pop() for d in data]
print(ids)
@pytest.mark.parametrize('a, b, c', data, ids=ids)
def test_add(a, b, c):
    assert add(a, b) == c